package org.check.SQL;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.check.Util.XmlParser;
import org.check.VO.DBConnVO;

public class SqlExecutor {

	public static void main(String[] args) throws SQLException {
		//String fileName = "E:/log.txt";
		Connection conn = ConnectionFactory.getConnectionByType(XmlParser.generateDBVOList("conns_config.xml").get(0));
		//String sql = ReadFromFile.read(fileName);
		String sql = "select * from all_users";
		try {
			Statement stmt = conn.createStatement();
			ResultSet res = stmt.executeQuery(sql);
			while(res.next()){
				System.out.println(res.getString(1));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public static ResultSet getRS(String versionId, DBConnVO dbConnVO, String selectStr, String startDate, String endDate, String filter) throws SQLException{
		Connection conn = ConnectionFactory.getConnectionByType(dbConnVO);
		String sqlStr = SqlLoader.loadByVersionType(versionId, dbConnVO.getDbtype(), selectStr, startDate, endDate, filter);
		Statement stmt = conn.createStatement();
		System.out.println("%%%"+sqlStr);
		ResultSet res = stmt.executeQuery(sqlStr);
		return res;
	}
	
}
